<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/pintuer.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/admin.css">
    <script src="${pageContext.request.contextPath}/admin/js/jquery.js"></script>
    <script src="${pageContext.request.contextPath}/admin/js/pintuer.js"></script>  
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head"><strong class="icon-reorder"> 菜单列表</strong></div>
  <div class="padding border-bottom">
      <ul class="search" style="padding-left:10px;">
        <li> <a class="button border-yellow" href="${pageContext.request.contextPath}/system/menu/add"><span class="icon-plus-square-o"></span> 添加菜单 	</a></li>
        <li>菜单类型:
          <select id="menuType" class="input" onchange="changesearch()" style="width:120px; line-height:17px; display:inline-block">
            <option value="">全部</option>
            <option value="0">系统菜单</option>
            <option value="1">应用菜单</option>
          </select>
          <li>
          	 菜单编码:&nbsp;<input type="text" placeholder="搜索菜单编码" id="menuCode" class="input" style="width:140px; line-height:17px;display:inline-block" />&nbsp;
          </li>	
          <li>	
          	 菜单名称:&nbsp;<input type="text" placeholder="搜索菜单名称" id="menuName" class="input" style="width:140px; line-height:17px;display:inline-block" />&nbsp;
          <li>
                                     页数:&nbsp;<select id="pageNum" name="s_isvouch" class="input" onchange="changesearch()"  style="width:60px; line-height:17px;display:inline-block">&nbsp;&nbsp;
          </select>
          </li>
          <a href="javascript:void(0)" class="button border-main icon-search" onclick="doSearch()" > 搜索</a></li>
      	  <a href="javascript:void(0)" class="button border-main icon-undo"  onclick="reset()" > 重置</a></li>
      </ul>
    </div>
  <table class="table table-hover text-center">
    <tr id="tbHead">
      <th width="10">菜单编码</th>  
      <th width="10">菜单名称</th>  
      <th width="50">菜单路径</th>  
      <th width="50">菜单类型</th>
      <th width="160">操作</th>
    </tr>
  </table>
</div>
<script>

$(function(){
	$.ajax({
	 	type:'post',
	 	url:'${pageContext.request.contextPath}/system/menu/showData',
	 	data:{pageNo:1,pageSize:10},
	 	dataType:'json',
	 	cache:false,
	 	success:function(data)
	 	{	
	 		if(data.success)
	 		{
	 			$("#tbHead").after("");
	 			var dataList = data.data;
	 			var totalRow = data.totalRow;
	 			var totalPage = data.totalPage;	
	 			for(var element=0;element<dataList.length;element++){
	 				var htmlCode = buildTable(dataList[element]);
		 			$("#tbHead").after(htmlCode);
	 			}
	 			var htmlCodeStr= "";
	 			for(var pageStart = 1;pageStart<=totalPage;pageStart++){
	 				htmlCodeStr+="<option value='"+pageStart+"'>"+pageStart+"</option>"
	 			}
	 			$("#pageNum").html(htmlCodeStr);
	 		}
	 		else
	 		{
	 			alert(data.message);
	 		}
	 	},
	 	error:function(data)
	 	{
	 		alert('系统出现异常!');
	 	}
	});
	
});

function del(id){
	if(confirm("您确定要删除吗?")){
		
	}
}
function buildTable(element){
		var htmlTemplate = 
		  "<tr id='tbBody'>" +
	      "<td>"+element.menuCode+"</td>"+ 
	      "<td>"+element.menuName+"</td>"+ 
	      "<td>"+element.menuPath+"</td>"+
	      "<td>"+element.menuType+"</td>"+      
	      "<td><div class='button-group'>"+
	        "<a type='button' class='button border-main' href='javascript:void(0)' onclick='edit('"+element.id+"')'><span class='icon-edit'></span>修改</a>"+
	        "<a class='button border-red' href='javascript:void(0)' onclick='return del(17)'><span class='icon-trash-o'></span> 删除</a>"+
	        "<a class='button border-yellow' href='javascript:void(0)' onclick='return del(17)'><span class='icon-filter'></span> 禁用</a>"+
	      "</div>"+
	     " </td>"+
	    "</tr>";
	 return htmlTemplate;
}

function reset(){
	$("#menuPath").val("");
	$("#menuCode").val("");
	$("#menuType").val("");
	$("#pageNum").val("1");
}

function doSearch(){
	var pageNum = $("#pageNum").val();
	$.ajax({
	 	type:'post',
	 	url:'${pageContext.request.contextPath}/system/menu/showData',
	 	data:{pageNo:pageNum,pageSize:10},
	 	dataType:'json',
	 	cache:false,
	 	success:function(data)
	 	{	
	 		if(data.success)
	 		{
	 			$("#tbHead").after("");
	 			var dataList = data.data;
	 			var totalRow = data.totalRow;
	 			var totalPage = data.totalPage;	
	 			for(var element=0;element<dataList.length;element++){
	 				var htmlCode = buildTable(dataList[element]);
		 			$("#tbHead").after(htmlCode);
	 			}
	 			var htmlCodeStr= "";
	 			for(var pageStart = 1;pageStart<=totalPage;pageStart++){
	 				htmlCodeStr+="<option value='"+pageStart+"'>"+pageStart+"</option>"
	 			}
	 			$("#pageNum").html(htmlCodeStr);
	 		}
	 		else
	 		{
	 			alert(data.message);
	 		}
	 	},
	 	error:function(data)
	 	{
	 		alert('系统出现异常!');
	 	}
	});
}
</script>
</body></html>